package com.skymxc.wandroidtodo.data.pref;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;

import com.skymxc.wandroidtodo.APP;
import com.skymxc.wandroidtodo.entity.UserInfo;

/**
 * <p>
 *
 * </p>
 *
 * @author 孟祥超
 * <p>
 * date: 2021/12/2  7:42 上午
 */
public class PrefUtils {
    private static final String KEY_USER_NAME = "key.username";
    private static final SharedPreferences pref = APP.context.getSharedPreferences("common", Context.MODE_PRIVATE);

    public static void saveUserInfo(UserInfo userInfo) {
        pref.edit()
                .putString(KEY_USER_NAME, userInfo.getUsername())
                .apply();
    }

    public static boolean userIsExist() {
        String string = pref.getString(KEY_USER_NAME, null);
        return !TextUtils.isEmpty(string);
    }

    public static void removeUser() {
        pref.edit()
                .remove(KEY_USER_NAME)
                .apply();
    }
}
